/* 表单验证 */
function validate_required(field,checkid,alerttxt) { //检测表单是否为空
	var cid=document.getElementById(checkid);
	var btn=document.getElementById("submit");
	with (field) {
		if (value==null||value=="") {
			cid.innerHTML="<span style=\"color:red;\">"+alerttxt+"</span>";
			field.style.cssText='border:1px solid red;';
			btn.disabled=true;
			return false;
		} else {
			cid.innerHTML="<span style=\"color:#22B630;\">输入正确！</span>";
			field.style.cssText='';
			btn.disabled=false;
			return true;
		}
	}
}
function validate_email(field,checkid,alerttxt) { //检测邮箱地址合法性
	var cid=document.getElementById(checkid);
	var btn=document.getElementById("submit");
	with (field) {
		apos=value.indexOf("@")
		dotpos=value.lastIndexOf(".")
		if (apos<1||dotpos-apos<2) {
			cid.innerHTML="<span style=\"color:red;\">"+alerttxt+"</span>";
			field.style.cssText='border:1px solid red;';
			btn.disabled=true;
			return false;
		} else {
			cid.innerHTML="<span style=\"color:#22B630;\">输入正确</span>";
			field.style.cssText='';
			btn.disabled=false;
			return true;
		}
	}
}
function validate_length(field,checkid,alerttxt,l) { //检测字符串长度合法性
	var cid=document.getElementById(checkid);
	var btn=document.getElementById("submit");
	with (field) {
		if (value.length<l) {
			cid.innerHTML="<span style=\"color:red;\">"+alerttxt+"</span>";
			field.style.cssText='border:1px solid red;';
			btn.disabled=true;
			return false;
		} else {
			cid.innerHTML="<span style=\"color:#22B630;\">输入正确</span>";
			field.style.cssText='';
			btn.disabled=false;
			return true;
		}
	}
}
function validate_form(thisform,formid,check_id,method,errortxt,l) { //验证当前表单
	with (thisform) {
		switch(method) {
			case "required":
				if (validate_required(thisform,check_id,errortxt)==false) {
					thisform.focus();
					return false;
				}
				break;
			case "email":
				if (validate_email(thisform,check_id,errortxt)==false) {
					thisform.focus();
					return false;
				}
				break;
			case "length":
				if (validate_length(thisform,check_id,errortxt,l)==false) {
					thisform.focus();
					return false;
				}
				break;
		}
	}
}